package AbstractRational;

public abstract class Operating {
	
	int numerator;
	int denominator;
	 public abstract Operating yunsuan(Operating r);
	Operating(){
		
	}
	Operating(int a,int b){
		if(a==0){
			numerator=0;
			denominator=1;
		}
		else{
			setNumeratorAndDenominator(a,b);
		}
	}
       
    	void setNumeratorAndDenominator(int a,int b){
    		int c=f(Math.abs(a),Math.abs(b));
    		numerator=a/c;
    		denominator=b/c;
    		if(numerator<0&&denominator<0){
    			numerator=-numerator;
    			denominator=-denominator;
    		}
    	}
    	int getNumerator(){
    		return numerator;
    	}
    	int getDenominator(){
    		return denominator;
    	}
    	int f(int a,int b){
    		if(a<b){
    			int c=a;
    			a=b;
    			b=c;
    		}
    		int r=a%b;
    		while(r!=0){
    			a=b;
    			b=r;
    			r=a%b;
    		}
    		return b;
    	}
}
